package jobqueue;

import java.util.Date;

import objects.MessageCodes;
import objects.cluster.ClusterInfo;
import objects.predictors.ProbaInfo;
import objects.shared.Message;
import objects.shared.WorkPacket;
import objects.user.UserInfo;

import utils.Utils;

public class JobQueueInfo {
	private WorkPacket workPacket;
	private Date schedule;
	private ClusterInfo clusterInfo;
	
	public JobQueueInfo(WorkPacket wp,Date s, ClusterInfo c)
	{
		this.workPacket = wp;
		this.schedule = s;
		this.clusterInfo = c;
	}
	public JobQueueInfo(WorkPacket wp,ProbaInfo probaInfo, UserInfo ui)
	{
		this.workPacket = wp;
		this.schedule = probaInfo.h_prob.time;
		this.clusterInfo = ui.clusterMap.get(probaInfo.cluster);
	}
	
	public void sheduleAt(Date d)
	{
		this.schedule = (Date) d.clone();
	}
	public boolean isBefore(Date d)
	{
		return schedule.compareTo(d) <= 0;
	}
	public Date getSchedule()
	{
		return this.schedule;
	}
	public void submitJob()
	{
		try{
			//Utils.out("JOB SUBMISSION: "+ji.jname+" "+ji.clu+" "+schedule);
			if(clusterInfo.isConnected) {
				clusterInfo.sendMessage(workPacket);
			}
			
			//TODO what if cluster is not online anymore?? 
			
		}catch(Exception e){e.printStackTrace();}
	}
}
